// px 转换 rem 的函数
@function px2rem($px) {
  @return ($px / 37.5) + rem;
}

// 转换 px 到 rem 的混入
@mixin px2rem($property, $px-values) {
  $rem-values: ();
  
  @each $value in $px-values {
    @if $value == 0 or $value == auto {
      $rem-values: append($rem-values, $value);
    } @else {
      $rem-values: append($rem-values, px2rem($value));
    }
  }
  
  #{$property}: $rem-values;
}

// 响应式布局
@mixin responsive($property, $px-values) {
  #{$property}: $px-values;
  @include px2rem($property, $px-values);
}

// Flexbox 布局混入
@mixin flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

@mixin flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

@mixin flex-start {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

@mixin flex-end {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

@mixin flex-column {
  display: flex;
  flex-direction: column;
}

@mixin absolute-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

// 响应式断点混入
@mixin mobile {
  @media (max-width: 767px) { @content; }
}

@mixin tablet {
  @media (min-width: 768px) and (max-width: 1023px) { @content; }
}

@mixin desktop {
  @media (min-width: 1024px) { @content; }
}

// 按钮混入
@mixin button-base {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  font-size: 1rem;
  font-weight: 500;
  transition: all 0.3s ease;
  
  &:hover {
    transform: translateY(-1px);
  }
  
  &:active {
    transform: translateY(0);
  }
}

@mixin button-primary($bg-color: #42b883, $text-color: white) {
  @include button-base;
  background-color: $bg-color;
  color: $text-color;
  
  &:hover {
    background-color: darken($bg-color, 10%);
    box-shadow: 0 4px 8px rgba($bg-color, 0.3);
  }
}

@mixin button-secondary($bg-color: transparent, $text-color: #42b883, $border-color: #42b883) {
  @include button-base;
  background-color: $bg-color;
  color: $text-color;
  border: 2px solid $border-color;
  
  &:hover {
    background-color: $border-color;
    color: white;
  }
}

// 卡片混入
@mixin card-base {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: box-shadow 0.3s ease;
  
  &:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  }
}

@mixin card-elevated {
  @include card-base;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  
  &:hover {
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2);
  }
}

// 文本混入
@mixin text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@mixin text-multiline-truncate($lines: 2) {
  display: -webkit-box;
  -webkit-line-clamp: $lines;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

// 动画混入
@mixin fade-in($duration: 0.3s) {
  animation: fadeIn $duration ease-in-out;
}

@mixin slide-up($duration: 0.3s) {
  animation: slideUp $duration ease-out;
}

@mixin pulse($duration: 2s) {
  animation: pulse $duration infinite;
}

// 动画关键帧
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

// 工具混入
@mixin clearfix {
  &::after {
    content: '';
    display: table;
    clear: both;
  }
}

@mixin hide-scrollbar {
  -ms-overflow-style: none;
  scrollbar-width: none;
  
  &::-webkit-scrollbar {
    display: none;
  }
}

@mixin gradient($start-color, $end-color, $direction: to right) {
  background: linear-gradient($direction, $start-color, $end-color);
}

@mixin box-shadow($level: 1) {
  @if $level == 1 {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  } @else if $level == 2 {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  } @else if $level == 3 {
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
  }
} 